package com.hb.znpt.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hb.znpt.BR;
import com.hb.znpt.R;
import com.hb.znpt.adapter.LesseeAdapter;
import com.hb.znpt.bean.CheckBean;
import com.hb.znpt.bean.LesseeBean;
import com.hb.znpt.databinding.ActivityLesseeBinding;
import com.hb.znpt.viewmodel.LesseeViewModel;
import com.unitlib.base.base.BaseActivity;

import java.util.List;

public class LesseeActivity extends BaseActivity<ActivityLesseeBinding, LesseeViewModel> {

    private LesseeAdapter adapter;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_lessee;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        initBackTitle(binding.toolbar);
        initRecyclerView();
    }

    @Override
    public void initViewObservable() {
        viewModel.listData.observe(this, new Observer<List<LesseeBean>>() {
            @Override
            public void onChanged(List<LesseeBean> beans) {
                adapter.setList(beans);
            }
        });
    }

    /**
     * Init recycler view.
     * 初始化RecyclerView
     */
    public void initRecyclerView() {
        adapter = new LesseeAdapter();
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                LesseeBean bean = (LesseeBean) adapter.getItem(position);
                Intent intent = new Intent(LesseeActivity.this, LandActivity.class);
                intent.putExtra("data", bean);
                startActivity(intent);
            }
        });
    }
}
